from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-15 14:02:55.951699
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 15, Dec, 2022
Time: 14:03:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.2259
Nobs: 871.000 HQIC: -51.5302
Log likelihood: 11490.4 FPE: 3.45820e-23
AIC: -51.7187 Det(Omega_mle): 3.12054e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295414 0.049845 5.927 0.000
L1.Burgenland 0.105615 0.034103 3.097 0.002
L1.Kärnten -0.106851 0.018308 -5.836 0.000
L1.Niederösterreich 0.214964 0.071588 3.003 0.003
L1.Oberösterreich 0.088216 0.067817 1.301 0.193
L1.Salzburg 0.249675 0.036202 6.897 0.000
L1.Steiermark 0.029874 0.047551 0.628 0.530
L1.Tirol 0.127505 0.038734 3.292 0.001
L1.Vorarlberg -0.062353 0.033269 -1.874 0.061
L1.Wien 0.062162 0.060627 1.025 0.305
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064063 0.102555 0.625 0.532
L1.Burgenland -0.009883 0.070166 -0.141 0.888
L1.Kärnten 0.049267 0.037668 1.308 0.191
L1.Niederösterreich -0.173657 0.147290 -1.179 0.238
L1.Oberösterreich 0.364165 0.139532 2.610 0.009
L1.Salzburg 0.286071 0.074485 3.841 0.000
L1.Steiermark 0.108480 0.097834 1.109 0.268
L1.Tirol 0.318612 0.079694 3.998 0.000
L1.Vorarlberg 0.024258 0.068450 0.354 0.723
L1.Wien -0.025349 0.124739 -0.203 0.839
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199228 0.025803 7.721 0.000
L1.Burgenland 0.090006 0.017654 5.098 0.000
L1.Kärnten -0.009081 0.009478 -0.958 0.338
L1.Niederösterreich 0.267405 0.037059 7.216 0.000
L1.Oberösterreich 0.113830 0.035107 3.242 0.001
L1.Salzburg 0.052704 0.018741 2.812 0.005
L1.Steiermark 0.015643 0.024616 0.635 0.525
L1.Tirol 0.101743 0.020051 5.074 0.000
L1.Vorarlberg 0.056366 0.017223 3.273 0.001
L1.Wien 0.113209 0.031385 3.607 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105102 0.026485 3.968 0.000
L1.Burgenland 0.047648 0.018121 2.629 0.009
L1.Kärnten -0.016879 0.009728 -1.735 0.083
L1.Niederösterreich 0.197083 0.038038 5.181 0.000
L1.Oberösterreich 0.278306 0.036035 7.723 0.000
L1.Salzburg 0.118061 0.019236 6.137 0.000
L1.Steiermark 0.100324 0.025266 3.971 0.000
L1.Tirol 0.126469 0.020581 6.145 0.000
L1.Vorarlberg 0.069664 0.017678 3.941 0.000
L1.Wien -0.026596 0.032215 -0.826 0.409
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131237 0.047881 2.741 0.006
L1.Burgenland -0.054127 0.032760 -1.652 0.098
L1.Kärnten -0.037171 0.017587 -2.114 0.035
L1.Niederösterreich 0.166723 0.068768 2.424 0.015
L1.Oberösterreich 0.132912 0.065146 2.040 0.041
L1.Salzburg 0.290745 0.034776 8.361 0.000
L1.Steiermark 0.034347 0.045678 0.752 0.452
L1.Tirol 0.162358 0.037208 4.364 0.000
L1.Vorarlberg 0.107826 0.031959 3.374 0.001
L1.Wien 0.066756 0.058239 1.146 0.252
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059847 0.037930 1.578 0.115
L1.Burgenland 0.038340 0.025951 1.477 0.140
L1.Kärnten 0.049901 0.013932 3.582 0.000
L1.Niederösterreich 0.227505 0.054475 4.176 0.000
L1.Oberösterreich 0.271416 0.051606 5.259 0.000
L1.Salzburg 0.058910 0.027548 2.138 0.032
L1.Steiermark -0.007087 0.036184 -0.196 0.845
L1.Tirol 0.157324 0.029474 5.338 0.000
L1.Vorarlberg 0.068951 0.025316 2.724 0.006
L1.Wien 0.075554 0.046134 1.638 0.101
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185030 0.045449 4.071 0.000
L1.Burgenland 0.018803 0.031095 0.605 0.545
L1.Kärnten -0.060375 0.016693 -3.617 0.000
L1.Niederösterreich -0.093533 0.065274 -1.433 0.152
L1.Oberösterreich 0.177708 0.061836 2.874 0.004
L1.Salzburg 0.060856 0.033009 1.844 0.065
L1.Steiermark 0.229533 0.043357 5.294 0.000
L1.Tirol 0.488786 0.035317 13.840 0.000
L1.Vorarlberg 0.050309 0.030335 1.658 0.097
L1.Wien -0.055236 0.055280 -0.999 0.318
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157912 0.051663 3.057 0.002
L1.Burgenland -0.000044 0.035347 -0.001 0.999
L1.Kärnten 0.066398 0.018976 3.499 0.000
L1.Niederösterreich 0.200947 0.074198 2.708 0.007
L1.Oberösterreich -0.069264 0.070290 -0.985 0.324
L1.Salzburg 0.220300 0.037522 5.871 0.000
L1.Steiermark 0.112517 0.049285 2.283 0.022
L1.Tirol 0.084157 0.040146 2.096 0.036
L1.Vorarlberg 0.123348 0.034482 3.577 0.000
L1.Wien 0.105500 0.062838 1.679 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358332 0.030501 11.748 0.000
L1.Burgenland 0.006354 0.020869 0.304 0.761
L1.Kärnten -0.025215 0.011203 -2.251 0.024
L1.Niederösterreich 0.229100 0.043806 5.230 0.000
L1.Oberösterreich 0.155942 0.041499 3.758 0.000
L1.Salzburg 0.053053 0.022153 2.395 0.017
L1.Steiermark -0.016514 0.029097 -0.568 0.570
L1.Tirol 0.121161 0.023702 5.112 0.000
L1.Vorarlberg 0.071541 0.020358 3.514 0.000
L1.Wien 0.047692 0.037099 1.286 0.199
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038206 0.158732 0.180824 0.168183 0.141177 0.126129 0.065036 0.219493
Kärnten 0.038206 1.000000 0.000714 0.131609 0.026585 0.098948 0.432560 -0.049633 0.101473
Niederösterreich 0.158732 0.000714 1.000000 0.345091 0.169439 0.311706 0.125815 0.191087 0.341476
Oberösterreich 0.180824 0.131609 0.345091 1.000000 0.234340 0.341408 0.176931 0.179847 0.272772
Salzburg 0.168183 0.026585 0.169439 0.234340 1.000000 0.152808 0.135857 0.152651 0.140731
Steiermark 0.141177 0.098948 0.311706 0.341408 0.152808 1.000000 0.158894 0.147623 0.094155
Tirol 0.126129 0.432560 0.125815 0.176931 0.135857 0.158894 1.000000 0.122097 0.166407
Vorarlberg 0.065036 -0.049633 0.191087 0.179847 0.152651 0.147623 0.122097 1.000000 0.019473
Wien 0.219493 0.101473 0.341476 0.272772 0.140731 0.094155 0.166407 0.019473 1.000000